package com;

import java.util.ArrayList;
import java.util.Scanner;

public class register {
    public static void register(ArrayList<User> user)
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String name = sc.next();
        String password1;
        String password2;
        while(true)
        {
            System.out.println("请输入密码");
            password1 = sc.next();
            password2 = sc.next();
            if (password1.equals(password2))
            {
                break;
            }
            else
            {
                System.out.println("两次输入的密码不一致请重新输入");
            }
        }
        String phone;
        while(true)
        {
            System.out.println("请输入手机号:");
            phone = sc.next();
            String c = phone.substring(0,1);
            char[] arr = phone.toCharArray();
            boolean judge = false;
            for(int i =0;i<phone.length();i++)
            {
                if(arr[i]<'0'||arr[i]>'9')
                {
                    judge = true;
                    break;
                }
            }
            if(phone.length()!=11||c.charAt(0)=='0'||judge)
            {
                System.out.println("输入不合法，请重新输入");
            }
            else
            {
                break;
            }
        }
        String id_card;
        while(true)
        {
            System.out.println("请输入身份证号");
            id_card = sc.next();
            String c = id_card.substring(0,1);
            String end = id_card.substring(id_card.length()-1);
            char[] arr = id_card.toCharArray();
            boolean isnumber = true;
            for(int i=0;i<id_card.length()-1;i++)
            {
                if(arr[i]>'9'||arr[i]<'0')
                {
                    isnumber = false;
                    break;
                }
            }
            if(id_card.length()<18||!isnumber||c.charAt(0)=='0'
                    ||(!end.equalsIgnoreCase("x")&&(end.charAt(0)<'0'||end.charAt(0)>'0')))
            {
                System.out.println("输入错误，请重新输入");
            }
            else
            {
                break;
            }
        }
        User u = new User(name,password1,id_card,phone);
        user.add(u);

    }

}
